//package com.wangm.elasticsearch;
//
//import org.apache.http.HttpHost;
//import org.apache.http.auth.AuthScope;
//import org.apache.http.auth.UsernamePasswordCredentials;
//import org.apache.http.client.CredentialsProvider;
//import org.apache.http.impl.client.BasicCredentialsProvider;
//import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
//import org.elasticsearch.client.RestClient;
//import org.elasticsearch.client.RestClientBuilder;
//import org.elasticsearch.client.RestHighLevelClient;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
//
///**
// * @author wangmeng
// * @since 2022/1/13
// */
//@Configuration
//public class EsConfig extends AbstractElasticsearchConfiguration {
//
//    @Value("${elasticsearch.uris}")
//    private String uri;
//    @Value("${elasticsearch.username}")
//    private String username;
//    @Value("${elasticsearch.password}")
//    private String password;
//
//    @Override
//    @Bean(destroyMethod = "close")
//    public RestHighLevelClient elasticsearchClient() {
//        // 阿里云Elasticsearch集群需要basic auth验证。
//        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//        //访问用户名和密码为您创建阿里云Elasticsearch实例时设置的用户名和密码，也是Kibana控制台的登录用户名和密码。
//        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "VckEJzW19xccGNlv"));
//
//        // 通过builder创建rest client，配置http client的HttpClientConfigCallback。
//        // 单击所创建的Elasticsearch实例ID，在基本信息页面获取公网地址，即为ES集群地址。
//        RestClientBuilder builder = RestClient.builder(new HttpHost("es-cn-2r42if1bb0004qo23.public.elasticsearch.aliyuncs.com", 9200, "http"))
//                .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
//                    @Override
//                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
//                        return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
//                    }
//                });
//
//        // RestHighLevelClient实例通过REST low-level client builder进行构造。
//        RestHighLevelClient highClient = new RestHighLevelClient(builder);
//        return highClient;
//    }
//
//}
